﻿<%@page import="java.io.IOException"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="s" uri="/struts-tags"%>

<%!public void commentList(List<Map<String,Object>> commentList,JspWriter out,Integer id,String home){
		try{
		
		for(Map<String,Object> comment:commentList){
			if(comment.get("reply")!=null){

				out.println("<li class='comment even depth-comment-"+comment.get("id")+"' id='li-comment-"+comment.get("id")+"'>");
				out.println("<article id='comment-"+comment.get("id")+"' class='comment'>");
				out.println("<footer class='comment-meta'>");
				out.println("<div class='comment-author vcard'>");
				out.println("<span class='fn'><a href='"+comment.get("userHome")+"' rel='external nofollow' class='url'>"+comment.get("userName")+" </a> </span><img alt='' src='"+home+"/upload/header/"+comment.get("header")+"' height='38' width='38' class='avatar avatar-68 photo' > <span> 在 "+comment.get("commTime")+"  说道：</span>");
				out.println("</div>	");			
				out.println("<br />");
				out.println("</footer>");
				out.println("<div class='comment-content'><p>"+comment.get("content")+"</p>");
				out.println("</div>");
				out.println("<div class='reply'>");
				out.println("<a class='comment-reply-link' href='details?id="+id+"&#038;replytocom="+comment.get("id")+"#respond' onclick=\"return addComment.moveForm('comment-"+comment.get("id")+"', '"+comment.get("id")+"','respond', '"+comment.get("id")+"')\">回复 <span>&darr;</span></a>");		
				out.println("</div>");
				out.println("</article>");

				out.println("<ul class='children'>");
				List<Map<String,Object>> replyList=(List<Map<String,Object>>)comment.get("reply");
				commentList(replyList,out,id,home);
				out.println("</li>");
				out.println("</ul>");
				
			}
			else{
				out.println("<li class='comment even depth-comment-"+comment.get("id")+"' id='li-comment-"+comment.get("id")+"'>");
				out.println("<article id='comment-"+comment.get("id")+"' class='comment'>");
				out.println("<footer class='comment-meta'>");
				out.println("<div class='comment-author vcard'>");
				out.println("<span class='fn'><a href='"+comment.get("userHome")+"' rel='external nofollow' class='url'>"+comment.get("userName")+" </a> </span><img alt='' src='"+home+"/upload/header/"+comment.get("header")+"' height='38' width='38'class='avatar avatar-68 photo'/> <span> 在 "+comment.get("commTime")+"  说道：</span>");
				out.println("</div>	");			
				out.println("<br />");
				out.println("</footer>");
				out.println("<div class='comment-content'><p>"+comment.get("content")+"</p>");
				out.println("</div>");
				out.println("<div class='reply'>");
				out.println("<a class='comment-reply-link' href='details?id="+id+"&#038;replytocom="+comment.get("id")+"#respond' onclick=\"return addComment.moveForm('comment-"+comment.get("id")+"', '"+comment.get("id")+"','respond', '"+comment.get("id")+"')\">回复 <span>&darr;</span></a>");		
				out.println("</div>");
				out.println("</article>");
				out.println("</li>");
			}
		}
		
		}
		catch(IOException e){
			e.printStackTrace();
		}
		
	}%>


<s:set  name="page" value="page" scope="request"/>

<ol class="commentlist">
	<s:iterator var="comments" id="comment" value="%{comments}" status="i">
		<li class="comment even thread-even depth-<s:property value='id'/>"
			id="li-comment-<s:property value='id'/>">
			<article id="comment-<s:property value='id'/>" class="comment">
				<footer class="comment-meta">
					<div class="comment-author vcard">
						<img alt='' src='${home}/upload/header/<s:property value='%{header}'/>'
							class='avatar avatar-68 photo' height='68' width='68' /><span class="fn"><a href='${comm.userHome }' rel='external nofollow' class='url'><s:property value="%{userName}" /> </a> </span> 在 <a href="#comment-${comm.cnt }"><time pubdate datetime='<s:property value="%{commTime}"/>'><s:property value="%{commTime}" /></time> </a> <span class="says">说道：</span>
							 <span style="float:right; "><s:property value='%{(#request.page-1)*5+#i.count}'/> #</span>
					</div>
					<div class="comment-content">
						<p>
							<s:property value="%{content}" escape="false" />
						</p>
					</div>
					<s:if test="%{#comment.reply!=null}">
						<s:set value="%{#comment.reply}" id="commentList" scope="request" var="commentList" />
						<ul class='children'>
						<%
							commentList((List<Map<String, Object>>) request.getAttribute("commentList"),out, Integer.parseInt(request.getParameter("id")),request.getAttribute("home").toString());
						%>
						</ul>
					</s:if>

					<div class="reply">
						<a class='comment-reply-link'
							href='?id=${param.id}&#038;replytocom=<s:property value='id'/>#respond'
							onclick='return addComment.moveForm("comment-<s:property value='id'/>", "<s:property  value="id"/>", "respond", "<s:property  value="id"/>")'>回复
							<span>&darr;</span> </a>
					</div>
					<!-- .reply -->
				</footer>
			</article></li>
	</s:iterator>
</ol>
	<jsp:include page="comment_page.jsp"/>

<div id="respond" class="comment-respond">
	<h3 id="reply-title" class="comment-reply-title">
		发表评论 <small><a rel="nofollow" id="cancel-comment-reply-link"
			href="?id=${param.id}#respond" style="display:none;">取消回复</a> </small>
	</h3>
	<form action="${home}/comment/add" method="post" id="commentform"
		class="comment-form">
		<p class="comment-form-comment">
			<label for="comment">评论</label>
			<textarea id="comment" name="t.content" cols="45" rows="7"></textarea>
		</p>
		<input type="submit" id="submit" value="发表评论" /> 
		<input type='hidden' name='t.area.cid' value='${param.id}' />
		<input type='hidden' name='t.replyComm.commentId' id='comment_parent' value='' />
		<input type='hidden' name='t.forward' value='${home}/<s:property value='%{#forward}'/>' />
		
	</form>
</div>
<!-- #respond -->